package week3.day15;

import java.util.Objects;

/**
 * @Author fengzihao
 * @Date 2024-04-29 19:34
 */
public class TestGetClass {
    public static void main(String[] args) {
        A a1 = new A();
        A a2 = new A();
        B b1 = new B();
        Class aClassa1 = a1.getClass();
        Class aClassa2 = a2.getClass();
        Class aClassb1 = b1.getClass();
        System.out.println(aClassb1 == aClassa2);
        System.out.println(aClassb1 == aClassa1);
        System.out.println(aClassa1 == aClassa2);

    }

    // 判断是否是同一个类
    public static boolean isSameType(Object obj1, Object obj2) {
        if (obj1 == null || obj2 == null) {
            return false;
        }
        return obj1.getClass().equals(obj2.getClass());
    }
}
class A{
    int age;
    String name;
    double price;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof A a)) return false;
        return age == a.age && Double.compare(price, a.price) == 0 && Objects.equals(name, a.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name, price);
    }
}

class B{

}
